import React from 'react';
import { cn } from '../../utils/cn';

interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
  label?: string;
  error?: string;
  icon?: React.ReactNode;
  variant?: 'default' | 'glass';
}

const Input: React.FC<InputProps> = ({
  label,
  error,
  icon,
  variant = 'glass',
  className,
  ...props
}) => {
  const baseClasses = 'w-full px-4 py-3 rounded-xl transition-all duration-200 focus:outline-none focus:ring-4';
  
  const variants = {
    default: 'bg-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 focus:ring-blue-300 dark:focus:ring-blue-800 focus:border-blue-500 dark:focus:border-blue-400',
    glass: 'bg-white/80 dark:bg-gray-700/80 border border-gray-200/50 dark:border-gray-600/50 backdrop-blur-sm focus:ring-blue-300 dark:focus:ring-blue-800 focus:border-blue-500 dark:focus:border-blue-400'
  };

  const errorClasses = error ? 'border-red-500 focus:ring-red-300 dark:focus:ring-red-800 focus:border-red-500' : '';

  return (
    <div className="space-y-2">
      {label && (
        <label className="block text-sm font-semibold text-gray-700 dark:text-gray-300">
          {label}
        </label>
      )}
      <div className="relative">
        {icon && (
          <div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
            <div className="text-gray-400 dark:text-gray-500">
              {icon}
            </div>
          </div>
        )}
        <input
          className={cn(
            baseClasses,
            variants[variant],
            errorClasses,
            icon ? 'pl-10' : '',
            className
          )}
          {...props}
        />
      </div>
      {error && (
        <p className="text-sm text-red-600 dark:text-red-400 animate-slide-up">
          {error}
        </p>
      )}
    </div>
  );
};

export default Input;
